import axios from 'axios'
const instance = axios.create({
  baseURL: '/api',
  timeout: 20 * 1000,
  headers: {
    Authorization: `Basic ${localStorage.getItem('client')}`
  }
})

const UserModule = {
  namespaced: true,
  state: {},
  actions: {
    // 获取认证token
    async getAuthToken({ commit }, params) {
      return await instance.post(
        `/get_token?code=${params.code}&grant_type=${params.grant_type}&redirect_uri=${params.redirect_uri}/callback`
      )
    },
    // 刷新认证token
    async getRefreshToken({ commit }) {
      let url = `/refresh_token/?refresh_token=${localStorage.getItem(
        'refresh_token'
      )}&grant_type=refresh_token`
      return await instance.post(url)
    }
  }
}

export default UserModule
